#-*- coding: utf-8 -*-
'''
Created on Aug 27, 2012

@author: bbg
'''

from sqlalchemy import Integer, Column, String, MetaData, Table
from sqlalchemy.orm import mapper
    
class ConfigCookMethod(object):

    _Mapper_ = None
    _company_id_ = -1
    _shop_id_ = -1    
    def __init__(self):
        self.id = 0
        self.cook_class = 0
        self.cook_name = ''
        self.is_charge = ''
        self.cook_unit = ''
        self.cook_price = 0
        self.is_show_kitchen = 0
        self.retrieval_code = ''
        self.number_statistic_class = 0
        self.rank_id = 0
        
    def __repr__(self):
        return '<ConfigCookMethod id:%d,cook_class:%d,cook_name:%s,is_charge:%s'
        'cook_unit:%s,cook_price:%d,is_show_kitchen:%d,retrieval_code:%s,'
        'number_statistic_class:%d,rank_id:%d' % (self.id, self.cook_class, 
        self.cook_name, self.is_charge, self.cook_unit, self.cook_price,
        self.is_show_kitchen, self.retrieval_code, self.number_statistic_class, 
        self.rank_id)
                
    @staticmethod
    def doMapping(company_id, shop_id):
        '''
        按company_id分库，shop_id对应公司分店，每次生成对象前都要执行一次，以便map到正确的数据库上去
        '''
        if ConfigCookMethod._company_id_ == company_id and ConfigCookMethod._shop_id_ == shop_id:
            return
                
        if ConfigCookMethod._Mapper_ is not None:
            ConfigCookMethod._Mapper_.dispose()
            
        metaData = MetaData()
        configCookMethodTable = Table('config_cook_method', metaData,
                           Column('id', Integer, primary_key = True),
                           Column('cook_class', Integer),
                           Column('cook_name', String),
                           Column('is_charge', Integer),
                           Column('cook_unit', String),
                           Column('cook_price', Integer),
                           Column('is_show_kitchen', Integer),
                           Column('retrieval_code', String),
                           Column('number_statistic_class', Integer),
                           Column('rank_id', Integer),
                           schema = "shop_%s_%s" % (company_id, shop_id))
        
        ConfigCookMethod._Mapper_ = mapper(ConfigCookMethod, configCookMethodTable)
    